package com.xc.h05.controller.lishenao;

import com.xc.h05.entity.Heartknowledge;
import com.xc.h05.service.lishenao.HeartknowledgeService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class HeartknowledgeController {
    @Autowired
    private HeartknowledgeService heartknowledgeService;

    @GetMapping("/heartknowledge")
    public R selectAll(Integer pageNum,Integer pageSize,Heartknowledge heartknowledge) {
        return R.ok(heartknowledgeService.selectAll(pageNum, pageSize, heartknowledge));
    }

    @PostMapping("/addheartknowledge")
    public R insert(@RequestBody Heartknowledge record) {
        int i = heartknowledgeService.insert(record);
        if (i>0) {
            return R.ok("添加成功");
        }else {
            return R.error();
        }
    }

    @PutMapping("/updateheartknowledge")
    public R updateByPrimaryKeySelective(@RequestBody Heartknowledge record) {
        int i = heartknowledgeService.updateByPrimaryKeySelective(record);
        if (i>0) {
            return R.ok("修改成功");
        }else {
            return R.error();
        }
    }

    @DeleteMapping("/deleteheartknowledge")
    public R deleteByPrimaryKey(Long id) {
        int i = heartknowledgeService.deleteByPrimaryKey(id);
        if (i>0) {
            return R.ok("删除成功");
        }else {
            return R.error();
        }
    }

    @GetMapping("/heartknowledgebyid")
    public R selectByPrimaryKey(Long id) {
        Heartknowledge heartknowledge = heartknowledgeService.selectByPrimaryKey(id);
        if (heartknowledge!=null) {
            return R.ok(heartknowledge);
        }else {
            return R.error();
        }
    }



}
